<html><head><title>DatabaseQuery</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<font face="Verdana, sans-serif" size="2"><p align="center"><b><font size="4">DatabaseQuery()</font></b></p>
<p><b>Syntax</b></p><blockquote>
Result = <font color="#3A3966"><b>DatabaseQuery</b></font>(#Database, Request$ [, Flags])</blockquote>

</blockquote>
<b>Description</b><br><blockquote>

Executes a SQL query on the given database. Only queries which doesn't change the database 
records are accepted ('SELECT' like queries). To performs database modification, use <a href="databaseupdate.html">DatabaseUpdate()</a>. 

</blockquote><p><b>Parameters</b></p><blockquote>
<style type="text/css">
table.parameters { border-spacing: 0px; border-style: none; border-collapse: collapse; }
table.parameters td { border-width: 1px; padding: 6px; border-style: solid; border-color: gray; vertical-align: top; font-family:Arial; font-size:10pt; }
</style>
<table width="90%" class="parameters">
<tr><td width="10%"><i>#Database</i></td>
<td width="90%"> 
The database to use. 

</td></tr>
<tr><td><i>Request$</i></td>
<td> 
The SQL query to execute. 

</td></tr>
<tr><td><i>Flags (optional)</i></td>
<td> 
The flags to use. It can be one of the following value: 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#924B72">#PB_Database_StaticCursor</font> : performs the query to access the result in a sequential manner. It's not possible to rewind 
                              with <a href="previousdatabaserow.html">PreviousDatabaseRow()</a> or <a href="firstdatabaserow.html">FirstDatabaseRow()</a> on some drivers, but it is the faster way to get the data (default).
  <font color="#924B72">#PB_Database_DynamicCursor</font>: performs the query to access the result in a random manner using <a href="previousdatabaserow.html">PreviousDatabaseRow()</a> or <a href="firstdatabaserow.html">FirstDatabaseRow()</a>. 
                              It can be slower, or even unsupported on some drivers.
</font></pre>

</td></tr>
</table>
</blockquote><p><b>Return value</b></p><blockquote>

Returns nonzero if the query was successful or zero if it failed (due to a SQL error or a badly-formatted query). 

</blockquote><p><b>Remarks</b></p><blockquote>

If the query has succeeded then <a href="nextdatabaserow.html">NextDatabaseRow()</a> can be used to list returned records 
(see the example below). In the event of an error, the error text can be retrieved with 
<a href="databaseerror.html">DatabaseError()</a>. It is safe to use <a href="nextdatabaserow.html">NextDatabaseRow()</a> even if the request 
doesn't return any records. To get the number of columns returned by the query, use <a href="databasecolumns.html">DatabaseColumns()</a>. 
<br>
<br>
Once the query results aren't needed anymore, <a href="finishdatabasequery.html">FinishDatabaseQuery()</a> has to be called 
to release all the query resources. 
<br>
<br>
The query can contain place holders for bind variables. Such variables must be set before 
calling the function using <a href="setdatabasestring.html">SetDatabaseString()</a>, <a href="setdatabaselong.html">SetDatabaseLong()</a> etc. After executing the query, 
the bound variables are cleared and have to be set again for future calls. The syntax for specifying 
bind variables in SQL is dependent on the database. The example below demonstrate the syntax. 

</blockquote><p><b>Example</b></p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; First, connect to a database with an employee table</font>
  <font color="#3A3966">;</font>
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">DatabaseQuery</font>(<font color="#924B72">#Database</font>, &quot;SELECT * FROM employee&quot;) <font color="#3A3966">; Get all the records in the 'employee' table</font>
  
    <b><font color="#3A3966">While</font></b> <font color="#3A3966">NextDatabaseRow</font>(<font color="#924B72">#Database</font>) <font color="#3A3966">; Loop for each records</font>
      <b><font color="#3A3966">Debug</font></b> <font color="#3A3966">GetDatabaseString</font>(<font color="#924B72">#Database</font>, 0) <font color="#3A3966">; Display the content of the first field      </font>
    <b><font color="#3A3966">Wend</font></b>
  
<font color="#3A3966">    FinishDatabaseQuery</font>(<font color="#924B72">#Database</font>)
  <b><font color="#3A3966">EndIf</font></b>
</font></pre>

</blockquote><p><b>Example:</b> Bind variables with SQLite and ODBC</p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; SQLite and ODBC shares the same syntax for bind variables. It is indicated by the '?' character</font>
  <font color="#3A3966">;</font>
<font color="#3A3966">  SetDatabaseString</font>(<font color="#924B72">#Database</font>, 0, &quot;test&quot;)  
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">DatabaseQuery</font>(<font color="#924B72">#Database</font>, &quot;SELECT * FROM employee WHERE id=?&quot;)    
    <font color="#3A3966">; ...</font>
  <b><font color="#3A3966">EndIf</font></b>
</font></pre>

</blockquote><p><b>Example:</b> PostgreSQL</p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; PostgreSQL uses another syntax: $1, $2.. into the statement to indicate the undefined parameter</font>
  <font color="#3A3966">;</font>
<font color="#3A3966">  SetDatabaseString</font>(<font color="#924B72">#Database</font>, 0, &quot;test&quot;)  
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">DatabaseQuery</font>(<font color="#924B72">#Database</font>, &quot;SELECT * FROM employee WHERE id=$1&quot;)    
    <font color="#3A3966">; ...</font>
  <b><font color="#3A3966">EndIf</font></b>
</font></pre>

</blockquote><p><b>See Also</b></p><blockquote>

<a href="databaseupdate.html">DatabaseUpdate()</a>, <a href="nextdatabaserow.html">NextDatabaseRow()</a> 
<a href="setdatabasestring.html">SetDatabaseString()</a>, <a href="setdatabaselong.html">SetDatabaseLong()</a>, <a href="setdatabasequad.html">SetDatabaseQuad()</a>, <a href="setdatabasefloat.html">SetDatabaseFloat()</a>, <a href="setdatabasedouble.html">SetDatabaseDouble()</a> 
<a href="setdatabaseblob.html">SetDatabaseBlob()</a>, <a href="setdatabasenull.html">SetDatabaseNull()</a> 

</Blockquote><p><b>Supported OS </b><Blockquote>All</Blockquote></p><center><- <a href=databaseid.html>DatabaseID()</a> - <a href="index.html">Database Index</a> - <a href="databaseupdate.html">DatabaseUpdate()</a> -><br><br>

</body></html>